<template>
  <div>
    <el-table :data="list" style="width: 100%">
      <el-table-column prop="userName" label="账号"> </el-table-column>
      <!-- <template slot-scope="scope"> -->
      <el-table-column prop="nickName" label="昵称"></el-table-column>
      <!-- </template> -->
      <el-table-column prop="password" label="密码"> </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="primary" @click="yhEdit(scope.row._id)">修改</el-button>
          <el-button type="danger" @click="yhsc(scope.row._id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @current-change="pageChange"
      layout="prev, pager, next"
      :page-count="pages"
    >
    </el-pagination>
  </div>
</template>
<script>
import { yhGet,yhDelete } from '../../api/yonghu'
export default {
  data(){
    return {
      list:[],
      pages:1,
      aaa:'123'
    }
  },
  async created(){
    this.Res()
  },
  methods:{

    async Res(page = 1) {
      const res = await yhGet({ page });
      for(let i=0;i<res.data.users.length;i++){
      if(res.data.users[i].nickName){
        // console.log("true")
        res.data.users[i].nickName = res.data.users[i].nickName
      }else{
        res.data.users[i].nickName = 'humen'
      }
      }
      this.list = res.data.users;
      console.log(this.list)
      this.pages = res.data.pages;
    },
    async pageChange(page) {
      //console.log(page);
      this.Res(page);
    },
    yhEdit(id){
      this.$router.push({
        name:"yhEdit",
        query:{
          id
        }
      })
    },
    yhsc(id){
      this.$confirm("此操作将永久删除该账号, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true
      }).then(() => {
          console.log("111")
          yhDelete(id).then(res => {
            console.log(res);
            this.$router.go(0);
          });
          this.$message({
            type: "success",
            message: "删除成功!"
          });
        })
        .catch(err => {
          console.log(err)
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    }
  },
  filters:{
    // NickName(nickName){
    //   console.log(nickName)
    //   // return nickName.startsWith("")?"luckin human":nickName
    // }
  }
}
</script>
